<?php
/**
 *
 *
 *
 */
class Yz_Form_Element_Checkbox
    extends Yz_Form_Element_Input
{

    protected $name;
    protected $value = 0;


    /** render
     *
     */
    public function render(Yz_Template_Interface $template)
    {
        $checked = $this->value ? ' checked="checked"' : "";
        $o = <<<html
            <input type="checkbox" name="{$this->name}" value="1"{$checked} />\n
html;
        return $o;
    }


    /** validate input
     *
     */
    protected function validateType($input)
    {
        if (null === $input)
            $value = 0;
        else if ("1" === $input)
            $value = 1;
        else
            // other value indicates incorrect form
            // this error is not caught in parse()
            throw Yz_Form_Error_InvalidFormError::_new_();
        return $value;
    }



}
